package com.sessioncookie;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Cookie 默认浏览器关闭就失效.  如果setMaxAge，则浏览器关闭也可以保存
 * @classDesc: 功能描述:(获取Cookie)
 * http://localhost:8080/servlet-demo/GetCookieServlet
 */
@WebServlet("/GetCookieServlet")
public class GetCookieServlet extends HttpServlet {

	  @Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		    // 如果所有的Cookies信息
		  Cookie[] cookies = req.getCookies();
		  if(cookies!=null){
			  for (Cookie cookie : cookies) {
				System.out.println(cookie.getName()+"----"+cookie.getValue());
			}
		  }else{
			  System.out.println("没有任何Cookie信息");
		  }
		    
	}
	
}
